package org.example.filedemos;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.logging.Logger;

public class FileNIOFastCopy {

    private static final Logger LOG = Logger.getLogger(FileNIOFastCopy.class.getName());

    public static void main(String[] args) throws Exception{
        String originFile = FileNIOFastCopy.class.getResource("/filedemos/1.txt").getFile();
        String targetFile = FileNIOFastCopy.class.getResource("/filedemos/fast.txt").getFile();

        RandomAccessFile raFile = new RandomAccessFile(originFile, "rw");
        RandomAccessFile targetRaFile = new RandomAccessFile(targetFile, "rw");

        FileChannel originFileChannel = raFile.getChannel();
        FileChannel targetFileChannel = targetRaFile.getChannel();

        LOG.info("size =====>" + originFileChannel.size());
        originFileChannel.transferTo(0, originFileChannel.size(), targetFileChannel);
    }
}
